package com.dmlll.controller;

import com.alibaba.fastjson.JSON;
import com.dmlll.VO.InformationManagement;
import com.dmlll.VO.InformationManagementDTO;
import com.dmlll.pojo.FamilyPlanning;
import com.dmlll.service.FamilyPlanningService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class FamilyPlanningController {
    @Autowired
    private FamilyPlanningService familyPlanningService;

    @RequestMapping("/insertsPlanning")
    @ResponseBody
    public Integer insertsPlanning(FamilyPlanning planning){
        if(planning.getId()==null) {
            familyPlanningService.insertsPlanning(planning);
        }else {
            familyPlanningService.updatePlanning(planning);
        }
        return planning.getId();
    }

    //信息管理分页查
    @RequestMapping("/findAll")
    @ResponseBody
    public PageInfo<InformationManagement> findAll(@RequestParam(value = "pageNum",defaultValue = "1",required = false)Integer pageNum,
                                                   @RequestParam(value = "Sice",defaultValue = "5") Integer Sice,
                                                   InformationManagementDTO informationManagementDTO,
                                                   Integer id){


        int Grade=familyPlanningService.findGrade(id);
        System.out.println(Grade);
        Grade=Grade-1;
        PageInfo<InformationManagement> list=familyPlanningService.findAll(informationManagementDTO,pageNum,Sice,Grade);
        return list;
    }
    @RequestMapping("findFamilyPlanningById")
    @ResponseBody
    public FamilyPlanning findFamilyPlanningById(Integer id){
        return familyPlanningService.findFamilyPlanningById(id);
    }
}
